import {
  login
} from '../../utils/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const scene = decodeURIComponent(options.scene)
    wx.getSystemInfo({
      success: (result) => {
        wx.setStorageSync('systemInfo', result)
      },
    })
    if (scene === 'undefined') {
      this.login()
    } else {
      this.login(scene)
    }

  },
  /**
   * 登录
   */
  login(scene) {
    wx.login({
      timeout: 2000,
      success: res => {
        login({
          code: res.code,
          chiefUid: scene
        }).then(res => {
          if (res.data) {
            wx.setStorageSync('token', res.data.token)
            wx.setStorageSync('formal', res.data.formal)
            wx.setStorageSync('rate', res.data.rate)
            wx.setStorageSync('uid', res.data.uid)
          }
          wx.switchTab({
            url: '../home/home'
          })
        })
      }
    })
  }
})